<?php

namespace Database\Seeders;

use App\Models\System\Config;
use App\Models\System\Dict;
use Illuminate\Database\Seeder;

class DictSeeder extends Seeder
{
    public function run()
    {
        if (Dict::count() != 0) {
            return;
        }
        $data = [
            [
                'title' => 'dict.sex.title',
                'code' => 'sex',
                'items' => [
                    [
                        'title' => 'dict.sex.man',
                        'value' => 'man',
                    ],
                    [
                        'title' => 'dict.sex.woman',
                        'value' => 'woman',
                    ],
                ],
            ],
            [
                'title' => 'dict.sys_config_group.title',
                'code' => Config::DICT_GROUP_NAME,
                'items' => [
                    [
                        'title' => 'dict.sys_config_group.basic',
                        'value' => 'basic',
                    ],
                    [
                        'title' => 'dict.sys_config_group.auth',
                        'value' => 'auth',
                    ],
                    [
                        'title' => 'dict.sys_config_group.upload',
                        'value' => 'upload',
                    ],
                    [
                        'title' => 'dict.sys_config_group.email',
                        'value' => 'email',
                    ],
                ],
            ],
        ];
        // 开启字段过滤 数据库迁移会自动关闭
        Dict::unguard(false);
        Dict::createDictItems($data);
        // 执行完后关闭
        Dict::unguard(true);
    }
}
